﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using MassOperations.vs2008.Model;

namespace MassOperations.vs2008.Reader
{
	class XmlStorageReader : IStorageReader
	{
		private readonly string _filename;

		public XmlStorageReader(string filename)
		{
			this._filename = filename;
		}

		#region IStorageReader Members

		public IEnumerable<StorageItem> ReadAll()
		{
			var xdoc = new XmlDocument();
			xdoc.Load(_filename);
			return 
				from XmlNode node 
				in xdoc.FirstChild.ChildNodes 
				select new StorageItem(node.Attributes["value"].Value, node.InnerText);
			
		}

		#endregion

		public override string ToString()
		{
			return new FileInfo(_filename).Name;
		}
	}
}
